<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function ajaxRequest(url) {
        return new Promise(function (resolve, reject) {
          let xhr = new XMLHttpRequest();
          xhr.open("GET", url, true);
          xhr.responseType = "json";
          xhr.onload = function () {
            resolve(xhr.response);
          };
          xhr.send();
        });
      }
      ///串行，一个一个来
      (async function () {
        try{
            let data1 = await ajaxRequest("data1.json");
            throw new Error('执行错误');
            let data2 = await ajaxRequest("data2.json");
            let data3 = await ajaxRequest("data3.json");
            console.log([data1, data2, data3]);
        }catch(error){
            console.log('进入catch');
            console.log(error);
        }
      })();
      //并行，一起来
      (async function () {
        let result = await Promise.all([
          ajaxRequest("data1.json"),
          ajaxRequest("data2.json"),
          ajaxRequest("data3.json"),
        ]);
        console.log(result);
      })();
    </script>
  </body>
</html>
